package application.controller;

import application.ATM;
import application.Account;
import application.ATMFrame;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;

import java.io.IOException;

public class LoginController {
    @FXML
    private TextField password;
    @FXML
    private TextField cardID;
    @FXML
    private Button submit;
    @FXML
    private Stage primaryStage;
    Parent tp;
    public void setNumOneAction(){
        password.setText(password.getText()+"1");
    }
    public void setNumTwoAction(){
        password.setText(password.getText()+"2");
    }
    public void setNumThreeAction(){
        password.setText(password.getText()+"3");
    }
    public void setNumFourAction(){
        password.setText(password.getText()+"4");
    }
    public void setNumFiveAction(){
        password.setText(password.getText()+"5");
    }
    public void setNumSixAction(){
        password.setText(password.getText()+"6");
    }
    public void setNumSevenAction(){
        password.setText(password.getText()+"7");
    }
    public void setNumEightAction(){
        password.setText(password.getText()+"8");
    }
    public void setNumNineAction(){
        password.setText(password.getText()+"9");
    }
    public void setNumZeroAction(){
        password.setText(password.getText()+"0");
    }

    public void Submit() {
        String passwd=password.getText();
        String cardId=cardID.getText();
        Account a=ATM.active(cardId,passwd);
        if(a!=null) {
            try {
                tp = FXMLLoader.load(getClass()
                        .getResource("../fxml/Main.fxml"));
                Scene tpScene = new Scene(tp);
                ATMFrame.stage.setScene(tpScene);

            } catch (IOException e1) {
                System.out.println("执行出错");
                e1.printStackTrace();
            }
        }
        else {
            Alert wr = new Alert(Alert.AlertType.INFORMATION,"");
            wr.setTitle("Wrong!");
            wr.setHeaderText("Wrong!");
            wr.show();
        }
    }
}
